AI Lessons
Lesson 21: Model pipelining - using object detection and image classifier

Purpose: To combine object detection and image classification models to build a complete AI processing pipeline that locates, crops, and analyzes specific visual data in real time.

No. of Classes

1 - (Time : 1 hour 30 minutes, Laptops/desktops : 10, Students strength : 15 to 20).

Materials Required

Laptop / Desktop with Internet connection / Wi-Fi.

A working webcam and code editor (p5.js Web Editor or VS Code).

Base starter project code for multi-model loading.

Prior knowledge
  • Real-time object detection with COCO-SSD / ml5.js
  • Exporting custom Teachable Machine image classifiers
  • Basic canvas image manipulation in p5.js
Exercises

Mini Project: Automated Object Inspection Pipeline



  • Students construct a multi-model pipeline that detects an object in real time, isolates its bounding region by cropping it, and displays both the visual crop and the detection output on screen.

Exercise 1 - Step 1: Recall the object detection model.



  • Initialize the pre-trained object detection model (e.g., COCO-SSD) on the live webcam feed using ml5.js and p5.js.
  • Draw bounding boxes and label tags around detected objects using their bounding box coordinates $(x, y, w, h)$.

Exercise 1 - Step 2: Crop the detected object from the output image and display the cropped image along with the detection result.



  • Extract the pixel area corresponding to the primary detected bounding box using p5.js image extraction (`get(x, y, w, h)`).
  • Render the dynamically cropped object snippet on screen in a dedicated preview box alongside the main webcam view and confidence scores.

Exercise 1 - Step 3: Pass the cropped image to a custom classifier.



  • Pass the live cropped image directly as input into a second pre-trained or custom image classifier model.
  • Display the final pipeline classification result below the cropped image.

Solutions



Teacher's Instruction:
  1. Introduce Model Pipelining Concepts to students - passing output from one model as input to another model, and how this can be used to build more complex AI systems.
  2. Explain latency and processing sequence: Model 1 must finish predicting before Model 2 can receive its input.
  3. Points to Ponder:
    • What happens if the first model fails to detect an object? How can we handle this gracefully in the pipeline?